import  axios  from  'axios'

import router  from '../../router'
let http=axios.create({
 
baseURL:'/api'
})

  //设置令牌token
//请求拦截
http.interceptors.request.use((req)=>{
//  console.log(req,'请求');
    let token=sessionStorage.getItem('user')?JSON.parse(sessionStorage.getItem('user')).token:''
        //   console.log(token);
        req.headers.authorization=token
       
      return req  //不拦截
})


//响应拦截
    http.interceptors.response.use((res)=>{
        if(res.data.code==403){
  //token失效返回到登录页
          router.push('/login')
        }
      return  res
    })
export default  http